﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Dijkstra_Belman_Ford
{
    public partial class FormGenerate : Form
    {
        public static Graf Graph;

        public FormGenerate()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            int wierzcholkow, krawedzi;

            wierzcholkow = (int)numWierzch.Value;
            krawedzi = (int)numKrawedz.Value;

            Graph = GenerateGraph(wierzcholkow, krawedzi);

            this.Close();
        }

        public static Graf GenerateGraph(int wierzcholkow, int krawedzi)
        {
            Graf g = new Graf(wierzcholkow);

            Random r = new Random();

            int x, y, z;

            for (int i = 0; i < wierzcholkow + krawedzi; i++)
            {
                if (i < wierzcholkow - 1)
                {
                    x = i;
                    y = i + 1;
                }
                else
                {
                    x =  r.Next(0, wierzcholkow);
                    y =  r.Next(0, wierzcholkow);
                    if (x == y)
                        do
                        {
                            x = r.Next(0, wierzcholkow);
                            y = r.Next(0, wierzcholkow);
                        }
                        while (x == y);
                }
                z = r.Next(0, wierzcholkow);
                g.waga[x, y] = z;
            }

            return g;
        }

        private void FormGenerate_Load(object sender, EventArgs e)
        {

        }

    }
}
